package com.hlhj.funlike_businessqzxd.utils;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;

import com.hlhj.funlike_businessqzxd.R;

/**
 * creat_user: zhengzaihong
 * Email:1096877329@qq.com
 * creat_date: 2018/6/25
 * creat_time: 9:48
 * describe 自定义 带删除线的TextView
 **/
public class DelTextView extends android.support.v7.widget.AppCompatTextView {

    private boolean flag;

    public DelTextView(Context context) {
        this(context, null);
    }


    public DelTextView(Context context, AttributeSet attrs) {

        this(context, attrs, 0);

    }

    public DelTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        final TypedArray a = getContext().obtainStyledAttributes(
                attrs, R.styleable.myTextStyle, defStyleAttr, 0);
        flag = a.getBoolean(R.styleable.myTextStyle_ishowdel, false);
    }

    @Override
    public void onDraw(Canvas canvas) {

        super.onDraw(canvas);

        if (flag) {
            Paint paint = new Paint();
            // 设置直线的颜色
            paint.setColor(getResources().getColor(R.color.gray));
            // 设置直线没有锯齿
            paint.setAntiAlias(true);

            // 设置线宽
            paint.setStrokeWidth((float) 1.0);

            // 设置直线位置
            canvas.drawLine(0, this.getHeight() / 2, this.getWidth(),

                    this.getHeight() / 2, paint);

        }
    }

    /**
     * @param flag true显示删除线  false不显示删除线
     * @return
     */
    public boolean setShow(boolean flag) {

        this.flag = flag;

        return flag;

    }

}
